import { getQaCategoryStatistics, getQaStatistics, doExportQaCategoryRecords, doExportQaRecords } from '@/services/datastatistics';
import { doRobotList } from '@/services/robotManagement';

export default {
  namespace: 'qaAnswerStatistics',

  state: {
    list: [],
    total: '',
  },
  effects: {
    *fetchRobotList({ payload, callback }, { call, put }) {
      const response = yield call(doRobotList, payload);
      if (callback && typeof callback === 'function') {
        callback(response);
      }
      yield put({
        type: 'save',
        payload: response,
      });
    },
    *fetchQaCategoryStatistics({ payload, callback }, { call, put }) {
      const response = yield call(getQaCategoryStatistics, payload);
      if (callback && typeof callback === 'function') {
        callback(response);
      }
      yield put({
        type: 'save',
        payload: response,
      });
    },
    *fetchQaStatistics({ payload, callback }, { call, put }) {
      const response = yield call(getQaStatistics, payload);
      if (callback && typeof callback === 'function') {
        callback(response);
      }
      yield put({
        type: 'save',
        payload: response,
      });
    },
    *exportQaCategoryRecords({ payload, callback }, { call, put }) {
      const response = yield call(doExportQaCategoryRecords, payload);
      if (callback && typeof callback === 'function') {
        callback(response);
      }
      yield put({
        type: 'save',
        payload: response,
      });
    },
    *exportQaRecords({ payload, callback }, { call, put }) {
      const response = yield call(doExportQaRecords, payload);
      if (callback && typeof callback === 'function') {
        callback(response);
      }
      yield put({
        type: 'save',
        payload: response,
      });
    },
  },

  reducers: {
    save(state, { payload }) {
      return {
        ...state,
        ...payload,
      };
    },
    clear() {
      return {
        list: [],
        total: '',
      };
    },
  },
};
